Repository navigation
🐛 fix(generator): 规范化非法 Java 标识符 - #96
Merged
Merged
Conversation
Owner
Author
|
问题复现: |
Owner
Author
|
实现实验:输入表名 |
Owner
Author
|
测试记录:核心模型、现代模板上下文、legacy 模板上下文和 AI 命名规则定向测试 143 passed;全量单测 638 passed,Ruff lint/format 均通过。此修复未建立前后运行时基准,性能未测量,不宣称性能提升。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
Closes #95
背景(Situation)
真实数据库允许连字符、空格、数字开头和 Java 保留字作为表名或列名。原有转换会把
order-item生成成非法的Order-item,把class直接作为 Java 字段;核心模型、现代模板和 legacy 模板还各自维护命名逻辑,生成源码可能无法编译。任务(Task)
建立共享的 Java 标识符规范化规则,覆盖分隔符、数字起始、空名称和关键字;保持数据库原始标识符用于 SQL/ORM 映射,并让所有生成路径使用同一规则。
行动(Action)
core.java_identifiers,统一 PascalCase、camelCase 和关键字后缀规则。TableInfo、TemplateContextBuilder、legacyTemplateContext与 AI 命名规则改用共享实现。验证(Verification)
环境:Windows 11,Python 3.12.12。
PYTHONPATH=src python -m pytest tests/unit/ -q:638 passed。ruff check src tests scripts与变更文件ruff format --check:通过。实验与证据(Evidence)
输入表名
order-item、列名class和123_display-name,输出分别为OrderItem、class_、generated123DisplayName,均通过 Java 标识符校验;tableName和原始列名仍保持数据库值。标准sys_user输出未改变。兼容性、风险与回滚